package com.io.example.demoparent.task;


import org.springframework.util.backoff.BackOffExecution;
import org.springframework.util.backoff.ExponentialBackOff;


public class FixedBackOff_02 {

    public static void main(String[] args) {
        withdrawAndKeep();
    }
    static long initialInterval = 100;           //初始间隔
    static double multiplier = 2.0;              //递增倍数
    static long maxInterval = 5 * 1000L;         //最大间隔
    static long maxElapsedTime = 50 * 1000L;

    private static void withdrawAndKeep() {
        ExponentialBackOff backOff = new ExponentialBackOff(initialInterval, multiplier);
        backOff.setMaxInterval(maxInterval);
        backOff.setMaxElapsedTime(maxElapsedTime);

        BackOffExecution execution = backOff.start( );

        while (true) {
            long value = execution.nextBackOff( );
            if (value == BackOffExecution.STOP) {
                System.out.println("value = " + value);
                break;
            } else {
                //在这里写你的重试逻辑
                System.out.println("-----------------");
            }
        }
    }
}
